<div class="sortlist mgt20">
    <h1>共 <{$count}> 个回答</h1>
</div>
<style>
#CommentList .media-content {
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-left: 40px
}

#CommentList .media-repter {
    background-color: #F7F7F7;
    padding: 10px;
}
.reply_btn{ cursor: pointer; }
</style>
<div id="CommentList" class="mgt20 after_div">
    <volist name="data" id="vo">
        <div class="media media-comment-<{$vo.id}>">
            <div class="media-content" style="margin:0px;">
                <div class="answer-content "> <span <if condition="$vo['is_best'] neq 1">style="display:none"</if>class="btn  btn-success a_bnt  btn-xs bnt_best_tag">已采纳</span> 
                    <{$vo[ 'content']}>
                </div>
                <if condition="$vo['comment']">
                    <div class="media-repter ">
                        <a style="color:#5cb85c" href="/User/index/user_id/<{$vo.comment.user_id}>" data-iduser="<{$vo.comment.user_id}>">
                            <{$vo.comment.user.nickname}>
                        </a>
                        <{:cutstr(strip_tags($vo[ 'comment'][ 'content']), "50")}>
                    </div>
                </if>
                <div class="muted mgt10">
                    <div class="s_left">
                        <a title="<{$vo.user.nickname}>" href="/User/index/user_id/<{$vo.user_id}>" target="_blank" class="small-avatar"> <img src="<{$vo.user.headimg}>" width="20" height="20"> <{$vo.user.nickname}> </a>
                        <php>$tag=Widget('BoxEdu/Index/user_tag',$vo['user_id'])</php>
                        <if condition="$tag eq '资深人士'">
                            <a class="label label-success">
                                <{$tag}>
                            </a>
                        </if> 
                       <span class="mgl10"><{$vo[ 'time_tran']}></span> 
                    </div>
                    <div class="pull-right">
                    <span data-nickname="<{$vo.user.nickname}>" onclick="reply_btn(this)" ontouchstart="reply_btn(this)" class="reply_btn" data-id="<{$vo.id}>"><i style="color: #ccc;" class="glyphicon glyphicon-comment" title="回复"></i></span>
                        </if>
                        <if condition="$topic_info['is_best'] neq 1 and $topic_info['user_id'] eq $user_info['user_id']">
                             <a href="<{:U('Subject/accept',array('comment_id'=>$vo['id']))}>" class="best_btn mgl10" confirm="1" title="确认采纳该回答吗？" data-type="ajaxGet"><i style="color:#00d449" class="glyphicon glyphicon-check" title="采纳"></i></a> 
                          </if>
                        <if condition="$vo['del_act'] eq 1"> 
                         <a href="/BoxSns/Home/Index/del_comment/comment_id/<{$vo['id']}>" data-id="<{$vo.id}>" confirm="1" title="确认删除该回答吗？" class="del_btn" data-type="ajaxGet"><i class="glyphicon glyphicon-trash" style="color: #ccc;" title="删除"></i></a> 
                        </if>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </volist>
</div>
<include file="Public:pager" />
<div class="clearfix"></div>
<if condition="!$is_mobile">
    <div class="sortlist mgt20">
        <h1>添加回答</h1>
    </div>
    <form action="/BoxSns/Home/Index/do_comment" id="addComment" class="mgt10" data-type="ajaxSubmit" method="post" style="padding-bottom:20px; ">
        <volist name="params['form']" id="vo">
            <input type="hidden" name="<{$key}>" value="<{$vo}>" />
        </volist>
        <input type="hidden" name="type" value="<{$params['type']}>" />
        <input type="hidden" name="pid" value="<{$params['topic_id']}>" />
        <input type="hidden" name="to_comment_id" value="0" />
        <textarea style="width:100%" name="content" data-type="kindeditor" placeholder="请在这里输入你的答案"></textarea>
        <div class="col-md-4" style="float:right; text-align:right">
            <button id="btnAsk" type="submit" class="btn mgt20 btn-block btn-success btn-large a_bnt">提交答案</button>
        </div>
        <div class="clearfix"></div>
    </form>
    <script type="text/javascript">
        $("#addComment").on("ajaxSubmitSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        dialog(data.msg)
    } else {
        $("#addComment").find('[data-type="kindeditor"]').val("");
        $("#addComment").find('[data-type="kindeditor"]').trigger("kindeditorChange");
        box_render(data.msg, $("#answerListItemHtml").html(), $("#CommentList"), "append");
    }
})
    </script>
</if>

<script type="text/html" id="answerListItemHtml">
<div>
    
    <div class="media media-comment-51752">
            <div class="media-content" style="margin:0px;">
                <div class="answer-content "> <span style="display:none" class="btn  btn-success a_bnt  btn-xs bnt_best_tag">已采纳</span> 
                     {{#items['content']}}                </div>
                     {{if items['comment']}}
                     <div class="media-repter ">
                        <a style="color:#5cb85c" href="/User/index/user_id/{{items.comment.user_id}}" data-iduser="{{items.comment.user_id}}">
                            {{items.comment.user.nickname}}                      </a>
                        {{items.comment.content}}                    </div>
                        {{/if}}

                                <div class="muted mgt10">
                    <div class="s_left">
                        <a title="{{items.user.nickname}}" href="/User/index/user_id/{{items.user_id}}" target="_blank" class="small-avatar"> <img src="{{items.user.headimg}}" width="20" height="20"> </a>
                                                                         {{items['time_tran']}}                   </div>
                    <div class="pull-right">
                    <a  onclick="reply_btn(this)" ontouchstart="reply_btn(this)"  data-nickname="{{items.user.nickname}}" data-id="{{items.user_id}}"><i style="color: #ccc;" class="glyphicon glyphicon-comment" title="回复"></i></a>
                        
                        <a href="/Subject/accept/comment_id/{{items.id}}" class="best_btn mgl10" confirm="1" title="确认采纳该回答吗？" data-type="ajaxGet"><i style="color:#00d449" class="glyphicon glyphicon-check" title="采纳"></i></a>&nbsp;
                         &nbsp;                        <a href="/BoxSns/Home/Index/del_comment/comment_id/{{items.id}}"" data-id="{{items.id}}"" confirm="1" title="确认删除该回答吗？" class="del_btn" data-type="ajaxGet"><i class="glyphicon glyphicon-trash" style="color: #ccc;" title="删除"></i></a>                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>

</div>

</script>
<script type="text/javascript">

//$(function(){
$(".best_btn").on("ajaxGetSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        dialog(data.msg);
    } else {
        dialog("回答采纳成功");
        $(this).parents(".media-content").find(".bnt_best_tag").show();
        $(this).parents("#CommentList").find(".best_btn").parent().hide();
    }
})

$(".del_btn").on("ajaxGetSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        dialog(data.msg);
    } else {
        dialog("删除成功");
        var id = $(this).attr("data-id");
        $(".media-comment-" + id).hide();
    }
})


$(function(){
    // $(".reply_btn").unbind(hiApp.device.click).bind(hiApp.device.click,function(){
    //  reply_btn(this);
    // })
})

//})
function clearRe(_this){
   $("#addComment").find("[name='to_comment_id']").val(0); 
   $('.page').find("#addComment textarea").val("");
   $('.page').find("#addComment textarea").attr("placeholder", "请在这里输入你的答案")
}

function reply_btn(_this) {
    var to_comment_id = $(_this).attr("data-id");
    var nickname = "@" + $(_this).attr('data-nickname');
    $("#addComment").find("[name='to_comment_id']").val(to_comment_id);
    if(view_type=="Web"){
        $("#btnAsk").focus();
    } 
    $(".page").find("#addComment textarea").focus();
     $(".page").find("#addComment textarea").attr("placeholder", nickname);
     $(".page").find("#addComment textarea").val("");
   if($("#addCommentDiv").length>0){
     hiApp.popup("#addCommentDiv");
   }
   
}
</script>
